package org.fast.develop.logicflow.ws;

import org.fast.develop.logicflow.runtime.enums.ExecuteDebugEnum;
import org.fast.develop.logicflow.ws.message.Message;
import org.fast.develop.logicflow.ws.message.MessageFactory;
import org.fast.develop.logicflow.ws.message.RunTimeMessage;
import org.fast.develop.logicflow.ws.message.StartMessage;
import org.fast.develop.logicflow.ws.thread.ThreadExecuteManager;

/**
 * @author czh
 * @version V1.0
 * @data Created on 2023-01-12 15:18
 */
public class LogicDebugService {

    private ThreadExecuteManager threadExecuteManager;

    public LogicDebugService(ThreadExecuteManager threadExecuteManager) {
        this.threadExecuteManager = threadExecuteManager;
    }

    public void run(String sessionId, String message) {
        Message messageObj = MessageFactory.create(message);
        if(ExecuteDebugEnum.start.equals(messageObj.getType())) {
            threadExecuteManager.start(sessionId, (StartMessage) messageObj);
        } else if (ExecuteDebugEnum.step_over.equals(messageObj.getType())){
            threadExecuteManager.run(sessionId,(RunTimeMessage)messageObj);
        }else if (ExecuteDebugEnum.step_into.equals(messageObj.getType())){

        }else if (ExecuteDebugEnum.resume_program.equals(messageObj.getType())){
            threadExecuteManager.run(sessionId,(RunTimeMessage)messageObj);
        }else if (ExecuteDebugEnum.end.equals(messageObj.getType())){
            threadExecuteManager.end(sessionId);
        }
    }
}
